package com.dianda.generic.controller.testController;

import com.alibaba.fastjson.JSONObject;
import com.dianda.generic.commons.utils.ResponseUtils;
import com.dianda.generic.service.testService.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Create by The_Answer on 2018/4/4.
 */
@RestController
@RequestMapping(value = "/generic")
public class TestController {

    @Autowired
    private TestService testService;

    @PostMapping(value = "/queryTest")
    public JSONObject queryTest(HttpServletRequest request){

        JSONObject rs = ResponseUtils.createErrorResponseBody();
        Map<String, Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        try{
            rs = testService.queryTest(params);
        }catch (Exception e){
            e.printStackTrace();
        }
        return rs;
    }

    @PostMapping(value = "/insertTest")
    public JSONObject insertTest(HttpServletRequest request){

        JSONObject rs = ResponseUtils.createErrorResponseBody();
        Map<String, Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        try{
            rs = testService.insertTest(params);
        }catch (Exception e){
            e.printStackTrace();
        }
        return rs;
    }

    @PostMapping(value = "/updateTest")
    public JSONObject updateTest(HttpServletRequest request){

        JSONObject rs = ResponseUtils.createErrorResponseBody();
        Map<String, Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        try{
            rs = testService.updateTest(params);
        }catch (Exception e){
            e.printStackTrace();
        }
        return rs;
    }

    @PostMapping(value = "/deleteTest")
    public JSONObject deleteTest(HttpServletRequest request){

        JSONObject rs = ResponseUtils.createErrorResponseBody();
        Map<String, Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        try{
            rs = testService.deleteTest(params);
        }catch (Exception e){
            e.printStackTrace();
        }
        return rs;
    }
}
